package com.aiti.ai.controller.ai;


import com.aiti.ai.dto.ai.GenerateEnterpriseDieldDto;
import com.aiti.ai.service.EnterpriseDealService;
import com.aiti.ai.service.ShowPremuEnterpriseService;
import com.aiti.ai.service.ai.MessageAssistant;
import com.aiti.ai.service.impl.ai.TestServiceImpl1;
import com.aiti.ai.tool.SearXNGWebSearchTool;
import com.aiti.base.core.utils.message.Message;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.service.AiServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class AiTestController {

    @Autowired
    private ShowPremuEnterpriseService service;
    @Autowired
    private TestServiceImpl1 testService;

    @Autowired
    private ChatLanguageModel model;

    @Autowired
    private SearXNGWebSearchTool searXNGWebSearchTool;

    @RequestMapping("/test")
    public Message test(@RequestParam(value = "id", required=false) String id){
        service.dealEnterprise(id);
        return Message.success();
    }

    @GetMapping("/shutdown")
    public String shutdown() {
        service.requestShutdown();
        return "Shutdown requested";
    }

    @PostMapping("/ai-service-chat-annon")
    public String chatAnnonation(@RequestBody Map<String,String> map) {
        return testService.testAiResponse(map.get("question"));
    }

    @PostMapping("/test-task")
    public String chatAnnonation2(@RequestBody Map<String,String> map) {
        testService.startTask();
        return "任务已提交";
    }

    @PostMapping("/testGenerate")
    public Message testGenerate(@RequestParam("name") String name){
        MessageAssistant assistant = AiServices.builder(MessageAssistant.class)
                .chatLanguageModel(model)
                .tools(searXNGWebSearchTool).build();
        GenerateEnterpriseDieldDto fieldDto = assistant.generateEnterpriseField(name);
        System.out.print("ai生成字段返回结果:"+fieldDto);
        return Message.success();
    }


}
